# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cryptography
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-python-${_realname}3")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
          "${MINGW_PACKAGE_PREFIX}-python-${_realname}3")
pkgver=39.0.0
pkgrel=2
pkgdesc="A package designed to expose cryptographic recipes and primitives to Python developers (mingw-w64)"
url='https://github.com/pyca/cryptography'
license=('Apache')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cffi")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-rust"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              #"${MINGW_PACKAGE_PREFIX}-python-iso8601"
              "${MINGW_PACKAGE_PREFIX}-python-pretend"
              #"${MINGW_PACKAGE_PREFIX}-python-cryptography-vectors"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-pytz")
source=(https://pypi.io/packages/source/c/cryptography/${_realname}-${pkgver}.tar.gz
        001-disable-abi3.patch)
sha256sums=('f964c7dcf7802d133e8dbd1565914fa0194f9d683d82411989889ecd701e8adf'
            'def2fee53afa97930c98cf1047f496a926bcf538f20972b14fc36facecd4372b')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}"/001-disable-abi3.patch
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # ${MINGW_PREFIX}/bin/python setup.py pytest
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
